<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>签到列表</title>
		<link rel="stylesheet" text="text.css" href="../../css.api.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/base.css">
	</head>
	<style>
		body {
			background-color: #F3F6F6;
			margin: 0px;
			padding: 0px;
			overflow-x: hidden;
			-webkit-user-select: none;
			-moz-user-select: none;
			-ms-user-select: none;
			user-select: none;
		}
		.beginSign {
			width: 100%;
			height: 45px;
			line-height: 45px;
			background-color: #F3F6F6;
			color: #999999;
			text-align: center;
			vertical-align: middle;
			font-size: 16px;
		}
		.section {
			width: 100%;
			height: 60px;
			position: relative;
			border: 1px solid #F1F0F1;
			background-color: #FFFFFF;
		}
		.signName {
			position: absolute;
			width: 100%;
			height: 18px;
			font-size: 14px;
			color: #222222;
			left: 10px;
			top: 10px;
		}
		.signTime {
			position: absolute;
			width: 60%;
			height: 20px;
			color: #ACACAC;
			font-size: 12px;
			top: 34px;
			left: 10px;
		}
		.signStateFrame {
			position: absolute;
			width: 16px;
			height: 16px;
			right: 60px;
			top: 33px;
		}
		.signStateImg {
			width: 16px;
			height: 16px;
		}
		.signStateFont {
			position: absolute;
			right: 10px;
			width: 40px;
			height: 16px;
			color: #ACACAC;
			font-size: 12px;
			top: 32px;
		}
		.mui-table-view-cell {
			width: 100%;
			height: 60px;
			position: relative;
			/* border: 1px solid #F1F0F1; */
			background-color: #FFFFFF;
		}
		.shuoming {
			font-size: 12px;
			color: #999999;
			text-align: left;
			width: 100%;
			height: 30px;
			vertical-align: middle;
			background-color: #FFFFFF;
			padding-top: 5px;
			/* padding-bottom: 5px; */
			padding-left: 20px;
			padding-right: 20px;
			line-height: 12px;
		}
		/* .left{
		 font-size: 12px;
		 color: #999999;
		 text-align: right;
		 width: 13%;
		 float: left;
		 height: 30px;
		 background-color: #FFFFFF;
		 line-height: 12px;
		 padding-top: 4px;
		 padding-left: 10px;
		 }
		 .right{
		 font-size: 12px;
		 color: #999999;
		 text-align: left;
		 width: 87%;
		 float: left;
		 height: 30px;
		 line-height: 12px;
		 background-color: #FFFFFF;
		 padding-right: 10px;
		 padding-top: 5px;
		 }
		 .shuo{
		 background-color: #FFFFFF;
		 width: 100%;
		 } */
		#main {
			border: solid 1px #dedede;
		}
	</style>
	<body>
		<div id="main"></div>
		<div class="noSign"   id="noData"  hidden="hidden">
			<img src="../../image/icon_img.png" width="60%">
			<p class="font16 top_15 base_dark_grey" >
				暂无数据
			</p>
		</div>
		<div class="loadFailure"  id="noNet" hidden="hidden">
			<img src="../../image/icon_img01.png" width="60%">
			<p class="" >
				数据加载失败
			</p>
			<p>
				请检查您的网络
			</p>
			<button type="button" class="mui-btn mui-btn-outlined" onclick="RefreshData()">
				重新加载
			</button>
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/jquery.min.js"></script>
	<script type="text/javascript" src="../../script/common.js"></script>
	<script type="text/javascript" src="../../script/timeStampTool.js"></script>
	<!--<script type="text/javascript" src="../../script/push.js"></script>-->
	<script type="text/javascript">
		var signId = '';
		var tmpArr = [];
		//存进行中的id
		var page = 1;
		var row = 10;
		var dataSource = [];
		var refreshCount = 0;
		apiready = function() {
			showProgress();
			loadNewData();
			//获取签到状态列表
			setRefreshHeader();
			setPullUpRefresh();
			api.addEventListener({
				name : 'signSuccess'
			}, function(ret, err) {
				loadNewData();
			});
		}
		function loadNewData() {
			dataSource = [];
			page = 1;
			loadData();
		}

		function loadMoreData() {
			page++;
			loadData();
		}

		function loadData() {
			var url = url_stuGetActivelist;
			var params = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				tid : 1,
				page : page, //互动类型
				rows : row, //恰当拿到状态
				cid : api.pageParam.cid,
				pid : api.pageParam.pid,
			};
			cfnetppPOST(url, params, true, function(data, status) {
				hideProgress();
				api.refreshHeaderLoadDone();
				if (status == 'success') {
					$('#noNet').hide();
					$('#noData').hide();
					$('#main').show();
					if (data.code == 200) {
						var dataPost = data.data;
						refreshCount = dataPost.length;
						if (dataPost != '' && dataPost.constructor == Array && dataPost.length > 0) {
							$('#noData').hide();
							$('#noNet').hide();
							$('#main').show();
							for (var i = 0; i < dataPost.length; i++) {
								dataSource.push(dataPost[i]);
							}
							initState(dataPost);
						} else {
							if (page == 1) {
								$('#noData').show();
								$('#noNet').hide();
							}
						}
					} else if (data.code == 108) {
						if (page == 1) {
							$('#noData').show();
							$('#noNet').hide();
							$('#main').hide();
						}
					} else {
						if (page == 1) {
							$('#noData').show();
							$('#noNet').hide();
							$('#main').hide();
						}
					}
				} else {
					if (page == 1) {
						$('#noData').hide();
						$('#noNet').show();
						$('#main').hide();
					}
				}
			});
		}

		function initState(data) {
			var str = '';
			tmpArr = [];
			//存放进行中状态的签到
			//      var finishedData = [];  //存放已结束状态的签到
			if (data.length > 0) {
				for (var i = 0; i < data.length; i++) {
					if (data[i].activestatus == 1)
						tmpArr.push(data[i]);
				}
			}
			//      for (var i = 0; i < dataSource.length; i++) {
			//          if (data[i].activestatus == 2) finishedData.push(data[i]);
			//      }
			var signYesOrNo = 0;
			var signName = "";
			//         alert("消息推送"+JSON.stringify(tmpArr[0]));
			if (tmpArr.length > 0) {//当前有最新的签到
				if (tmpArr[0].userstatus == 1) {
					$('#signName').html(tmpArr[0].name);
					//         alert("消息推送"+JSON.stringify(tmpArr[0]));
					signYesOrNo = tmpArr[0].id;
					signName = tmpArr[0].name;
					api.sendEvent({
						name : 'pushMessage_classroomMessage',
						extra : {
							id : signYesOrNo,
							name : signName,
							type : 10009,
							status : 1,
							jid : $api.getStorage('cfnetppjxid')
						}
					});
				}
			} else {
				signYesOrNo = 0;
				signName = "";
			}
			//      if (finishedData.length == 0) { //没有已结束签到
			//          $('#noData').show();
			//      }else{
			//          $('#noData').hide();
			//      }
			for (var i = 0; i < data.length; i++) {
				var item = data[i];
				//<img class="signStateImg" src="../../image/yiqiandao.png" alt="">
				var timeStr = "";
				if (item.starttime != null && item.starttime.length > 0&&item.starttime != 0) {
					timeStr = timeWithStamp3(item.starttime);
				} else {
					timeStr = timeWithStamp3(item.createtime);
				}
				var status = '';
				if (item.userstatus == 1) {
					status = "未签到";
				} else if (item.userstatus == 2) {
					status = "已签到";
				} else if (item.userstatus == 3) {
					status = "缺勤";
				} else if (item.userstatus == 4) {
					status = "事假";
				} else if (item.userstatus == 5) {
					status = "病假";
				} else if (item.userstatus == 6) {
					status = "迟到";
				} else if (item.userstatus == 7) {
					status = "早退";
				}
				if (item.activestatus == 1 && item.userstatus != 1) {
					if (item.userstatus == 1) {//未签到
						str += '<div class="mui-table-view-cell"><div class="signName">' + item.name + '</div><div class="signTime">' + timeStr + '</div><div class="signStateFrame"> <img class="signStateImg" src="../../image/queqin.png" alt=""></div><div class="signStateFont">' + status + '</div></div>';
					} else if (item.userstatus == 2) {//已签到
						str += '<div class="mui-table-view-cell"><div class="signName">' + item.name + '</div><div class="signTime">' + timeStr + '</div><div class="signStateFrame"> <img class="signStateImg" src="../../image/yiqiandao.png" alt=""></div><div class="signStateFont">' + status + '</div></div>';
					} else if (item.userstatus == 3) {//缺勤
						str += '<div class="mui-table-view-cell"><div class="signName">' + item.name + '</div><div class="signTime">' + timeStr + '</div><div class="signStateFrame"> <img class="signStateImg" src="../../image/queqin.png" alt=""></div><div class="signStateFont">' + status + '</div></div>';
					} else if (item.userstatus == 4) {//事假
						str += '<div class="mui-table-view-cell"><div class="signName">' + item.name + '</div><div class="signTime">' + timeStr + '</div><div class="signStateFrame"> <img class="signStateImg" src="../../image/shijia.png" alt=""></div><div class="signStateFont">' + status + '</div></div>';
					} else if (item.userstatus == 5) {//病假
						str += '<div class="mui-table-view-cell"><div class="signName">' + item.name + '</div><div class="signTime">' + timeStr + '</div><div class="signStateFrame"> <img class="signStateImg" src="../../image/bingjia.png" alt=""></div><div class="signStateFont">' + status + '</div></div>';
					} else if (item.userstatus == 6) {//迟到
						str += '<div class="mui-table-view-cell"><div class="signName">' + item.name + '</div><div class="signTime">' + timeStr + '</div><div class="signStateFrame"> <img class="signStateImg" src="../../image/chidao.png" alt=""></div><div class="signStateFont">' + status + '</div></div>';
					} else if (item.userstatus == 7) {//早退
						str += '<div class="mui-table-view-cell"><div class="signName">' + item.name + '</div><div class="signTime">' + timeStr + '</div><div class="signStateFrame"> <img class="signStateImg" src="../../image/zaotui.png" alt=""></div><div class="signStateFont">' + status + '</div></div>';
					}
				}
				if (item.activestatus == 2) {
					if (item.userstatus == 1) {//未签到
						str += '<div class="mui-table-view-cell"><div class="signName">' + item.name + '</div><div class="signTime">' + timeStr + '</div><div class="signStateFrame"> <img class="signStateImg" src="../../image/queqin.png" alt=""></div><div class="signStateFont">' + status + '</div></div>';
					} else if (item.userstatus == 2) {//已签到
						str += '<div class="mui-table-view-cell"><div class="signName">' + item.name + '</div><div class="signTime">' + timeStr + '</div><div class="signStateFrame"> <img class="signStateImg" src="../../image/yiqiandao.png" alt=""></div><div class="signStateFont">' + status + '</div></div>';
					} else if (item.userstatus == 3) {//缺勤
						str += '<div class="mui-table-view-cell"><div class="signName">' + item.name + '</div><div class="signTime">' + timeStr + '</div><div class="signStateFrame"> <img class="signStateImg" src="../../image/queqin.png" alt=""></div><div class="signStateFont">' + status + '</div></div>';
					} else if (item.userstatus == 4) {//事假
						str += '<div class="mui-table-view-cell"><div class="signName">' + item.name + '</div><div class="signTime">' + timeStr + '</div><div class="signStateFrame"> <img class="signStateImg" src="../../image/shijia.png" alt=""></div><div class="signStateFont">' + status + '</div></div>';
					} else if (item.userstatus == 5) {//病假
						str += '<div class="mui-table-view-cell"><div class="signName">' + item.name + '</div><div class="signTime">' + timeStr + '</div><div class="signStateFrame"> <img class="signStateImg" src="../../image/bingjia.png" alt=""></div><div class="signStateFont">' + status + '</div></div>';
					} else if (item.userstatus == 6) {//迟到
						str += '<div class="mui-table-view-cell"><div class="signName">' + item.name + '</div><div class="signTime">' + timeStr + '</div><div class="signStateFrame"> <img class="signStateImg" src="../../image/chidao.png" alt=""></div><div class="signStateFont">' + status + '</div></div>';
					} else if (item.userstatus == 7) {//早退
						str += '<div class="mui-table-view-cell"><div class="signName">' + item.name + '</div><div class="signTime">' + timeStr + '</div><div class="signStateFrame"> <img class="signStateImg" src="../../image/zaotui.png" alt=""></div><div class="signStateFont">' + status + '</div></div>';
					}
				}
			}
			if (page == 1) {
				$('#main').html(str);
			} else {
				$('#main').append(str);
			}
		}

		function RefreshData() {
			loadNewData();
			$('#noNet').hide();
		}

		function getNowFormatDate(ns) {
			var date = new Date(ns);
			var seperator1 = "-";
			var seperator2 = ":";
			var month = date.getMonth() + 1;
			var strDate = date.getDate();
			if (month >= 1 && month <= 9) {
				month = "0" + month;
			}
			if (strDate >= 0 && strDate <= 9) {
				strDate = "0" + strDate;
			}
			var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes();
			/*+ seperator2 + date.getSeconds();*/
			// alert(currentdate);
			var time = currentdate;
			return time;
		}

		function add0(m) {
			return m < 10 ? '0' + m : m
		}

		function format(shijianchuo) {
			
			return timeWithStamp(shijianchuo);
		}
	</script>
</html>